1798B - Three Sevens - CodeForces Solution


implementation

Please click on ads to support us..

C++ Code:

//Not the Best :)

#include <bits/stdc++.h>
using namespace std;

//DataTypes
using str =  string;
using ll  = long long;
using ld  = long double;
using vl  = vector<ll>;
using vd  = vector<ld>;
using vs  = vector<str>;
using vpl = vector<pair<ll,ll>>;
#define umap unordered_map
#define uset unordered_set

//Shorts
#define pus     push_back
#define pub     pop_back
#define ff       first
#define ss       second
#define dbg(x) cout<<#x<<" = "<<x<<'\n';

//Algorithms
#define sz(x)     ((ll)(x).size())
#define all(x)    x.begin(),x.end()
#define srt(x)    sort(all(x))
#define srtd(x)   sort(x.rbegin(),x.rend())
#define rev(x)    reverse(all(x));
#define Vmax(x)   *max_element(all(x))
#define Vmin(x)   *min_element(all(x))
#define Vsum(x)   accumulate(all(x),0ll)
#define lowB(v,x) *lower_bound(all(v),x) // >=x
#define upB(v,x)  upper_bound(all(v),x)-v.begin() // > x
#define ers(v,i)  v.erase(v.begin()+i) 
#define uniq(x)   x.erase(unique(all(x)),x.end())
#define NextP(x)  next_permutation(all(x))
#define PrevP(x)  prev_permutation(all(x))
#define cntB(x)   __builtin_popcountll(x)  
#define cntC(s,x) ll(count(all(s), x));

//loops
#define For(n)  for (ll i = 0; i < n; i++)
#define ForR(n) for (ll i = n-1; i >= 0; i--)
#define Forj(n) for (ll j = 0; j < n; j++)
#define For1(n) for (ll i = 1; i < n; i++)

//IO
#define nl      cout << "\n";
#define ya      cout << "YES\n";
#define na      cout << "NO\n";
#define inpt(v) For(sz(v)) cin >> v[i];
#define prt(v)  for(auto i:v) cout << i << " "; cout << "\n";

//Constants
const int M = 1e9+7; 
const int N = 2e5+5;
const ld pi = 3.141592653589793238;
const ll INF = 9e18;

ll n, a, b, c, k, m, x, y, q; str s;
 
//---------------------------------------------------------------------------------------------------------------------------------
//Let's Go :)

void solve()
{
    cin>>n;
    vl v(n);
    vl v3;
    map<ll,ll> mp1, mp2;
    vl vv[n];

    For(n){
        cin>>v[i];

        Forj(v[i]){
            cin>>x;
            vv[i].pus(x);
            mp1[x]++;
        }
    }
    

    For(n){
        k=0;
        Forj(vv[i].size()){
            mp2[vv[i][j]]++;
            if (mp1[vv[i][j]]==mp2[vv[i][j]] and k==0){ k=1; v3.pus(vv[i][j]);}
        }
        if (k==0){ cout<<-1; nl; return;}
    }
    prt(v3);


}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int t = 1;
    cin >> t;
    
    while(t--) solve();
    
    return 0;
}


Comments

Submit
0 Comments
More Questions

238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree